<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Croptype;

/* @var $this yii\web\View */
/* @var $model app\models\Croptype */
/* @var $form yii\widgets\ActiveForm */
?>

<?php
$column_name=Croptype::find()->select(['name',])->indexBy('id')->orderBy('code')->column();
$column_level=Croptype::find()->select(['level',])->indexBy('id')->orderBy('code')->column();
//echo var_dump($column_name);
//echo var_dump($column_level);
//echo $column_name['1'];
//echo $column_level['1'];
foreach($column_name as $key=>$value){
    $str="";
    for($j=0;$j<$column_level[$key];$j+=1)
        $str.='— ';
    $column_name[$key]=$str.$column_name[$key];
}
//for($i=1;$i<=sizeof($column_name);$i+=1)
//{
//    $str="";
//    for($j=0;$j<$column_level[$i];$j+=1)
//        $str.='— ';
//    //echo $str.$column_name[$i];
//    $column_name[$i]=$str.$column_name[$i];
//}
$column_name['1']="作物大类";
?>
<div class="croptype-form">

    <?php $form = ActiveForm::begin(); ?>

    <!--?= $form->field($model, 'id')->textInput(['maxlength' => true]) ?-->

    <?= $form->field($model, 'pid')->dropdownlist($column_name,
        ['prompt' => '选择父类别']) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'comment')->textInput(['maxlength' => true]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '添加' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end();?>

</div>
